package cc.linker.steplink.crm.controller.robot;

import cc.linker.steplink.crm.commons.model.PcUserInfo;
import cc.linker.steplink.crm.merchanth5.commons.UserInfoUtil;
import cc.linker.steplink.crm.service.RobotSurveyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Description: 机器人概况
 * @Author: wuyue
 * @Date: 2019/9/3 17:10
 * @Version: v1.8.3
 */
@RestController
@RequestMapping("/robot/survey")
public class RobotSurveyController {
    @Autowired
    private UserInfoUtil userInfoUtil;

    @Autowired
    private RobotSurveyService robotSurveyService;

    /**
     * @Description:热门阅读排行(前十的标签)
     * @Param:session
     * @Return:List<Map>
     * @Author: wuyue
     * @Date: 2019/9/4 9:36
     * @Version: v1.8.3
     */
    @GetMapping("/article")
    public List<Map<String, Object>> article(HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        return robotSurveyService.getArticleStatisticsByOrgId(userinfo.getOrgId());
    }

    /**
     * @Description:用户标签占比
     * @Param:session
     * @Return:List<Map>
     * @Author: wuyue
     * @Date: 2019/9/4 9:39
     * @Version: v1.8.3
     */
    @GetMapping("/label")
    public List<Map<String, Object>> label(HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        return robotSurveyService.getLabelPercentageByOrgId(userinfo.getOrgId());
    }

    /**
     * @Description:营销概况
     * @Param: session
     * @Return: 分页的List<Map>
     * @Author: wuyue
     * @Date: 2019/9/4 16:25
     * @Version: v1.8.3
     */
    @PostMapping("/market")
    public PageInfo market(@RequestBody Map<String, Object> map, HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        map.put("orgId", userinfo.getOrgId());
        return robotSurveyService.getMarketProfileByOrgId(map);
    }

    /**
     * @Description:成交数据
     * @Param: session
     * @Return: List<Map>
     * @Author: wuyue
     * @Date: 2019/9/4 17:27
     * @Version: v1.8.3
     */
    @GetMapping("/deal")
    public List<Map<String, Object>> deal(HttpServletRequest request) {
        PcUserInfo userinfo = this.userInfoUtil.getPcUserInfo(request);
        return robotSurveyService.getDealDataByOrgId(userinfo.getOrgId());
    }
}
